<template>
  <div class="box">
    <div class="top">
      <p class="title">实时游客统计</p>
      <p class="bg"></p>
      <p class="right">可预约总量<span>99999</span>人</p>
    </div>
    <div class="number">
      <span v-for="(item, index) in people" :key="index">{{ item }}</span>
    </div>
    <!-- 盒子将来echarts展示图形图标的节点 -->
    <div class="charts" ref="charts">123</div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import * as echarts from 'echarts';
//水球图拓展插件 - 需要在echarts之后导入
import 'echarts-liquidfill';

let people = ref('215908人');

//获取节点
let charts = ref();
let mycharts: echarts.ECharts | null = null;

onMounted(() => {
  //获取echarts类的实例
  mycharts = echarts.init(charts.value);
  //设置实例的配置项
  mycharts.setOption({
    //系列:决定你展示什么样的图形图标
    series: [{
      type: 'liquidFill',//系列
      data: [0.6, 0.4, 0.2],//展示的数据
      waveAnimation: true,//动画
      animationDuration: 3000,
      animationDurationUpdate: 1000,
      radius: '90%',//半径
      center: ['50%', '50%'], // 居中显示
      color: ['#294D99', '#156ACF', '#1598ED'], // 水波颜色
      backgroundStyle: {
        borderWidth: 2,
        borderColor: '#294D99',
        color: 'rgba(51, 51, 51, 0.1)'
      },
      outline: {//外层边框颜色设置
        show: true,
        borderDistance: 8,
        itemStyle: {
          color: 'none',
          borderColor: '#294D99',
          borderWidth: 8,
          shadowBlur: 20,
          shadowColor: 'rgba(0, 0, 0, 0.25)'
        }
      },
      label: {
        show: true,
        color: '#fff',
        insideColor: '#fff',
        fontSize: 16,
        formatter: function(param: any) {
          return Math.round(param.value * 100) + '%';
        }
      }
    }]
  })

  // 监听窗口大小变化，重新调整图表大小
  window.addEventListener('resize', handleResize);
})

// 窗口大小变化处理函数
const handleResize = () => {
  if (mycharts) {
    mycharts.resize();
  }
}

// 组件销毁时清理资源
onBeforeUnmount(() => {
  if (mycharts) {
    window.removeEventListener('resize', handleResize);
    mycharts.dispose();
    mycharts = null;
  }
})
</script>

<style scoped lang="scss">
.box {
  background: url(../../images/dataScreen-main-lb.png) no-repeat;
  background-size: 100% 100%;
  margin-top: 10px;

  .top {
    margin-left: 20px;

    .title {
      color: white;
      font-size: 20px;

    }

    .bg {
      width: 68px;
      height: 7px;
      background: url(../../images/dataScreen-title.png) no-repeat;
      background-size: 100% 100%;
      margin-top: 10px;
    }

    .right {
      float: right;
      color: white;
      font-size: 20px;

      span {
        color: yellowgreen;
      }
    }
  }

  .number {
    padding: 10px;
    margin-top: 30px;
    display: flex;


    span {
      flex: 1;
      height: 40px;
      text-align: center;
      line-height: 40px;
      background: url(../../images/total.png) no-repeat;
      background-size: 100% 100%;
      color: #29fcff;
    }
  }

  .charts {
    width: 100%;
    height: 270px;
  }
}
</style>
